<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------
namespace Common\Model;
use Think\Model;
class MobileinfoModel extends Model{
    protected $_validate = array(

    );
    /* 用户模型自动完成 */
    protected $_auto = array(

    );

    /*
     *     自动执行
     */
    public function automatic($uid=0){
        if(empty($uid)){
            $vo = $this->where('status=-1')->field('uid,token')->find();
        }else{
            $vo = $this->where('uid='.$uid)->field('uid,token')->find();
        }
        // return $vo;
        $api = new \Common\Extend\Api\ApiClient();
        $api = $api->mobile();
        $api->method            = 'mobile_report/v1/task/report';
        $api->token             = $vo['token'];
        // return $api;
        $info2=$api->Send('post','json')->data();
        // return $info2;
        if($info2['code']==0000){
           /* $content = $info2['data'];//content
            $result = $content['basicInfoCheck']['3']['result'];
            if(!empty($result)){
                $status = 1;
                $this->success('验证通过');
            }else{
                $status = 2;
            }*/
            $basicInfoCheck = $info2['data']['basicInfoCheck'];
            $status = 0;
            if(!empty($basicInfoCheck)){
                foreach($basicInfoCheck as $val){
                    if($val['item'] =='idcard_match'){
                        if($val['result'] ==1 || $val['result']==2){
                            $status = 2;
                        }
                    }
                }
            }
            $data = [
                'uid'       => $vo['uid'],
                'mobile'    => $info2['data']['basicInfo']['mobile'],
                'name'      => $info2['data']['basicInfo']['name'],
                'idCard'    => $info2['data']['basicInfo']['identityNo'],
                'address'   => $info2['data']['basicInfo']['nativeAddress'],
                'register'  => $info2['data']['basicInfo']['regTime'],
                'content'   => json_encode($info2['data']),
                'status'    => $status,
            ];
            $this->where('uid='.$this->uid)->save($data);
            // return $info2;
            return true;
        }else{
            return false;
        }
    }

}
